package com.axxc.jpa.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonBackReference;

@Entity
@Table(name = "t_student")
public class StudentEntity extends PersonEntity {

	private static final long serialVersionUID = 1L;
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "teacher_id")
	@JSONField(serialize = false)
	@JoinTable(name = "t_teacher_student", joinColumns = {
			@JoinColumn(name = "student_id", referencedColumnName = "id") }, inverseJoinColumns = {
					@JoinColumn(name = "teacher_id", referencedColumnName = "id") })
	@JsonBackReference // 解决序列化死循环
	private List<TeacherEntity> teachers = new ArrayList<>();

	public List<TeacherEntity> getTeachers() {
		return teachers;
	}

	public void setTeachers(List<TeacherEntity> teachers) {
		this.teachers = teachers;
	}


	// @Override
	// public String toString() {
	// TODO Auto-generated method stub
	// return String.format("id=%s,name=%s,age=%s", id,name.age);
	// }

}
